package com.ruyuan.eshop.buyer.controller.trade;

import com.ruyuan.eshop.buyer.domain.request.PayTradeRequest;
import com.ruyuan.eshop.framework.context.user.UserContext;
import com.ruyuan.eshop.common.domain.vo.BalancePayVO;
import com.ruyuan.eshop.common.service.trade.order.BalanceService;
import com.ruyuan.eshop.framework.context.user.model.Buyer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author pwd
 * @version 1.0
 **/
@Api(description = "预存款支付API")
@RestController
@RequestMapping("/api/v1.0/balance/pay")
@Validated
public class BalancePayController {

    @Autowired
    private BalanceService balanceService;


    /**
     * 使用预存款支付
     * @param sn
     * @param tradeType
     * @param payTradeRequest
     * @return
     */
    @ApiOperation(value = "使用预存款支付")
    @PostMapping(value = "/{trade_type}/{sn}")
    public BalancePayVO payTrade(@PathVariable(name = "sn") String sn, @PathVariable(name = "trade_type") String tradeType, @RequestBody PayTradeRequest payTradeRequest) {
        Buyer buyer = UserContext.getBuyer();
        return balanceService.balancePay(sn,buyer.getUid(),tradeType.toUpperCase(), payTradeRequest.getPassword());
    }

}
